﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CheckersLogic;



namespace CheckersUI
{
    public partial class GameSettings : Form
    {
        private eBoardSize m_BoardSize = eBoardSize.SixBySix;
        private int m_NumberOfPlayers;
        private GameBoard m_GameBoard = new GameBoard();
        private bool IsEndOfGame = false;

        public GameSettings()
        {
            this.InitializeComponent();
        }

        private void checkBoxPlayer2_Click(object sender, EventArgs e)
        {
            if (textBoxPlayer2Name.Enabled)
            {
                textBoxPlayer2Name.Enabled = false;
            }
            else
            {
                textBoxPlayer2Name.Enabled = true; 
            }
        }

        private void extendedRadioButton_Click(object sender, EventArgs e)
        {
            this.m_BoardSize = (sender as ExtendedRadioButton).BoardSize;
        }

        private void buttonDone_Click(object sender, EventArgs e)
        {
            Player PlayerX = new Player('X');
            Player PlayerO = new Player('O');
            
            if (textBoxPlayer1Name.Text != string.Empty)
            {
                PlayerO.Name = textBoxPlayer1Name.Text;                               
            }
            else
            {
                PlayerO.Name = "Player 1";
            }

            if (checkBoxPlayer2.Checked == true)
            {
                this.m_NumberOfPlayers = 2;
                if (textBoxPlayer2Name.Text != string.Empty)
                {
                    PlayerX.Name = textBoxPlayer2Name.Text;
                }
                else
                {
                    PlayerX.Name = "Player 2";
                }
            }
            else
            {
                this.m_NumberOfPlayers = 1;
                PlayerX.Name = "Computer";
            }

            while (!this.IsEndOfGame)
            {
                this.SetGameBoardSize();
                UICheckersBoard GameBoard = new UICheckersBoard(this.m_GameBoard, PlayerX, PlayerO, this.m_NumberOfPlayers);
                GameBoard.ShowDialog();
                if (GameBoard.DialogResult == DialogResult.No || GameBoard.DialogResult == DialogResult.Cancel)
                {
                    this.IsEndOfGame = true;
                }
            }
        }

        private void SetGameBoardSize()
        {
            int size = 6;
            switch (this.m_BoardSize)
            {
                case eBoardSize.SixBySix:
                    size = 6;
                    break;
                case eBoardSize.EightByEight:
                    size = 8;
                    break;
                case eBoardSize.TenByTen:
                    size = 10;
                    break;
                default:
                    break;
            }

            this.m_GameBoard.Size = size;
        }            
    }

    public enum eBoardSize
    {
        SixBySix,
        EightByEight,
        TenByTen
    }
}
